package main

import (
	"context"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"github.com/streadway/amqp"
	"git.900sui.cn/kc/rpcinterface/client/order"
	"strconv"
)

//订单超时未支付 关闭订单
func main() {
	mOrder := new(order.OrderPay).Init()
	defer mOrder.Close()
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("order.log.delyOrderQue"))
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("order.queue.delyOrderQue"), func(msg amqp.Delivery) {
		orderId, err  := strconv.Atoi( string(msg.Body) )
		if err != nil{
			utils.Logerr.Printf("订单支付超时，orderId 转换int失败，orderId:%s, err:%s", string(msg.Body), err)
			return
		}
		var reply bool
		err = mOrder.CloseOrder(context.Background(), &orderId, &reply)
		if err != nil {
			utils.Logerr.Printf("订单支付超时，业务处理任务调用失败，orderid:%d, err:%s", orderId, err)
		}
	})

	if err != nil {
		utils.Logerr.Printf("订单支付超时任务错误，err: %s", err.Error())
	}
}